package com.biostime.springdraw.modules.sd.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biostime.springdraw.common.service.CrudService;
import com.biostime.springdraw.modules.sd.dao.MoviecodeDao;
import com.biostime.springdraw.modules.sd.entity.Moviecode;

/**
 * 电影兑换码表Service
 * @author chenweicheng
 * @version 2016-05-03
 */
@Service
@Transactional
public class MoviecodeService extends CrudService<MoviecodeDao, Moviecode> {
	public Moviecode getOneCode(){
		return dao.getOneCode();
	}
	
	public void useCode(String id){
		dao.useCode(id);
	}
	
	public void recoveryMovie(){
		dao.recoveryMovie();
	}
	
	public void usingCode(){
		dao.usingCode();
	}
	
	
	/**
	 * 获取一张兑换码，并标记为已用
	 * @author chenweicheng
	 * @version 2016-05-05
	 */	
	public Moviecode getAndUse(){
		Moviecode code = getOneCode();
		if(code != null){
			useCode(code.getId());
			return code;
		}
		return null;
	}
	
	public int getNotUsedMoviecode(){
		return dao.getNotUsedMoviecode();
	}
}
